import mutiyi.manager.ConfigManager;
import mutiyi.pojo.User;

/**
 * Author:yang
 * Date:2024-03-06 9:06
 */
public class Main {
    public static void main(String[] args) {

        ConfigManager configManager = new ConfigManager();

        // 获取当前工作目录
        String currentDirectory = System.getProperty("user.dir");
        // 目标目录
        String targetDirectory = currentDirectory+"/config/src/main/resources";
        // 加载配置文件
        configManager.loadConfig(targetDirectory+"/config.properties");


        // 创建可配置对象
        try {
            User user = configManager.createObjectFromConfig(User.class);
            System.out.println(user.getPassword());
            System.out.println(user.getUsername());
            // 更新配置值
            configManager.updateConfig("username", "u");
            configManager.updateConfig("password", "p");

            // 保存更新后的配置到文件
            configManager.saveConfigToFile(targetDirectory+"/config.properties");

            // 再次创建对象并输出更新后的属性值
            User updatedUser = configManager.createObjectFromConfig(User.class);
            System.out.println("updated username: " + updatedUser.getUsername());
            System.out.println("updated password: " + updatedUser.getPassword());
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
